
package br.gen.seam.sqlserver;

import br.gen.seam.sqlserver.extract.columns.ExtractColumns;
import br.gen.seam.sqlserver.extract.schema.ExtractSchemas;
import br.gen.seam.sqlserver.extract.schema.SqlServerExtractSchemaException;
import br.gen.seam.sqlserver.extract.tables.ExtractTables;
import br.gen.seam.util.entity.Schema;
import br.gen.seam.util.jdbc.AbstractConnection;
import br.gen.seam.util.readerInfoDatabase.ReaderInfoDatabase;
import java.util.List;

/**
 *
 * @author Diego Araujo | diegogomesaraujo@gmail.com
 * @version 1.0
 */
public class SqlServer implements ReaderInfoDatabase {

    private String database;

    @Override
    public List<Schema> listAllSchemas() throws SqlServerException {
        try {
            List<Schema> schemas = new ExtractSchemas(database).getSchemas();
            schemas = new ExtractTables(database, schemas).getSchemas();
            schemas = new ExtractColumns(schemas).getSchemas();
            return schemas;
        } catch (SqlServerExtractSchemaException ex) {
            throw new SqlServerException(ex);
        }
    }

    @Override
    public void setDataConnection(String url, String database, String user, String password) {
        this.database = database;
        AbstractConnection connection = AbstractConnection.getInstance();
        connection.setDriverClass("net.sourceforge.jtds.jdbc.Driver");
        connection.setUrl(url);
        connection.setUser(user);
        connection.setPassword(password);
    }

}
